package app.server.project.core.websocket.model;

import app.server.project.core.websocket.WSDataModel;
import cn.hutool.json.JSONUtil;
import jakarta.websocket.Session;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@Slf4j
@AllArgsConstructor(staticName = "of")
public class PushUser {
    private long userId;
    private Session session;

    public void push(int cmd, Object data) {
        try {
            this.session.getBasicRemote().sendText(JSONUtil.toJsonStr(WSDataModel.of(cmd, data)));
        } catch (Exception e) {
            log.error("=========推送异常=========%s", e);
        }

    }
}
